local priority_low = 61
local priority_med = 91
local priority_hig = 121

-- 官方的新鲜度预设值，写在这里方便使用
-- TUNING.PERISH_ONE_DAY = 1*total_day_time*perish_warp
-- TUNING.PERISH_TWO_DAY = 2*total_day_time*perish_warp
-- TUNING.PERISH_SUPERFAST = 3*total_day_time*perish_warp
-- TUNING.PERISH_FAST = 6*total_day_time*perish_warp
-- TUNING.PERISH_FASTISH = 8*total_day_time*perish_warp
-- TUNING.PERISH_MED = 10*total_day_time*perish_warp
-- TUNING.PERISH_SLOW = 15*total_day_time*perish_warp
-- TUNING.PERISH_PRESERVED = 20*total_day_time*perish_warp
-- TUNING.PERISH_SUPERSLOW = 40*total_day_time*perish_warp

local foods_pl = {
    dish_pl_piggycorolla = {                 -- 猪猪晗
        test = function(cooker, names, tags) -- 烹饪配方函数
            return ((names.piggymimosa or 0) + (names.piggymimosa_cooked or 0)) >= 2 and
                (tags.meat and tags.meat >= 1) and names.refined_dust
        end,
        card_def = { ingredients = { { "piggymimosa", 2 }, { "monstermeat", 1 }, { "refined_dust", 1 } } }, -- 食谱卡的配方。为空时则无对应卡片产生
        priority = priority_hig,                                                                            -- 烹饪优先级。在烹饪条件都满足时，选择优先级最高的为结果。如果都一样按 weight 权重随机得到结果
        foodtype = FOODTYPE.GOODIES,                                                                        -- 食物类型
        secondaryfoodtype = FOODTYPE.ROUGHAGE,                                                              -- 第二食物类型
        hunger = 15,
        sanity = 25,
        health = 15, -- 食用回复属性
        -- perishtime = TUNING.PERISH_SLOW,                -- 新鲜度。为空时代表无新鲜度
        -- temperature = TUNING.HOT_FOOD_BONUS_TEMP,       -- 食用影响体温。大于0为升温，反之为降温。比较复杂最好借鉴官方数据
        -- temperatureduration = TUNING.FOOD_TEMP_AVERAGE, -- 食用后影响体温的时间。比较复杂最好借鉴官方数据
        -- cookpot_perishtime = 0,                         -- 在烹饪锅上的新鲜度时间，为空时则会使用 perishtime
        cooktime = 1.5,                       -- 烹饪时间。最终用时= cooktime*20，单位秒
        -- stacksize = 3,                                  -- 一次烹饪出的料理数量。默认为1
        potlevel = nil,                       -- 在烹饪锅上所用的通道类型。用来控制料理与锅的相对高度。"high"(高)、空值(中)、"low"(低)
        float = { 0.03, "small", 0.2, 1.1 },  -- (本mod专属)漂浮数据。底部切割比例、特效类型、特效高度、特效大小
        overridebuild = "dishes_pastoral",    -- 替换料理build。这样所有料理都可以共享一个build了。默认与料理名同名
        prefabs = { "buff_pl_piggycorolla" }, -- 所需要引用的预制物名
        -- tags = { "honeyed" },                                  -- 该料理额外添加的标签
        -- wet_prefix = STRINGS.WET_PREFIX.WETGOOP,               -- 用来替换潮湿时的前缀
        -- fireproof = true,                                      -- (本mod专属)该料理是否防火
        -- oneat_desc = STRINGS.UI.COOKBOOK.DISH_PL_PIGGYCOROLLA, -- 食谱中的食用效果的介绍语句
        oneatenfn = function(inst, eater)          -- 食用时会触发的特殊效果
            if eater.components.combat ~= nil then -- 这个buff需要攻击组件
                eater.time_l_piggycorolla = { add = TUNING.SEG_TIME * 16, max = TUNING.SEG_TIME * 30 }
                eater:AddDebuff("buff_pl_piggycorolla", "buff_pl_piggycorolla")
            end
        end,
        -- fn_common = function(inst)end, -- (本mod专属)预制物：服务器和客户端都会触发的函数
        -- fn_server = function(inst)end, -- (本mod专属)预制物：仅服务器会触发的函数
        -- notinitprefab = true, -- 兼容勋章的机制。此配方，不以勋章的通用方式生成调料后预制物

        -- 以下参数为棱镜兼容所需。不写则不兼容
        cook_need = "(烤)晗猪草≥2 肉度≥1 尘土块", -- 中文语言的料理配方，所需描述
        cook_cant = nil, -- 中文语言的料理配方，禁用描述
        recipe_count = 5 -- 需要使用多少种配方搭配才能完全解锁料理配方的描述。最多6，最少1。有的配方不一定有6种，所以不要乱写

        -- 以下参数，本mod不需要
        -- floater = { "med", 0.05, 0.65 }, --官方所用的漂浮数据
        -- OnPutInInventory = function(inst, owner)end, --放入物品栏时触发的函数。官方用来让玩家解锁一些无法食用料理的食谱数据
    }
}

------------
--棱镜
------------

if not SETS_PASTORAL.ENABLEDMODS["legion"] then
    foods_pl.dish_murmurananas = { --松萝咕咾肉
        test = function(cooker, names, tags)
            return (names.pineananas or names.pineananas_cooked) and (tags.meat and tags.meat >= 2) and
                (not tags.monster or tags.monster <= 1)
        end,
        card_def = { ingredients = { { "pineananas", 1 }, { "meat", 1 }, { "monstermeat", 1 }, { "twigs", 1 } } },
        priority = priority_med,
        foodtype = FOODTYPE.MEAT,
        hunger = 150,
        sanity = 12.5,
        health = 18,
        perishtime = TUNING.PERISH_MED,
        cooktime = 1,
        potlevel = "low",
        float = { nil, "small", 0.2, 1.05 },
        overridebuild = "dishes_pl_legion",

        cook_need = "(烤)松萝 肉度≥2",
        cook_cant = "怪物度≤1",
        recipe_count = 6
    }
    foods_pl.dish_sosweetjarkfruit = { -- 甜到裂开的松萝蜜
        test = function(cooker, names, tags)
            return names.pineananas and tags.frozen and (tags.sweetener and tags.sweetener >= 2)
                and not tags.monster and not tags.meat
        end,
        card_def = { ingredients = { { "pineananas", 1 }, { "ice", 1 }, { "honey", 2 } } },
        priority = priority_med,
        foodtype = FOODTYPE.VEGGIE,
        hunger = 18,
        sanity = 24,
        health = 0,
        perishtime = TUNING.PERISH_MED * 3,
        cooktime = 0.5,
        stacksize = 2,
        potlevel = "low",
        float = { 0.02, "small", 0.2, 0.9 },
        overridebuild = "dishes_pl_legion",
        tags = { "honeyed" },

        cook_need = "松萝 冰度 甜度≥2",
        cook_cant = "怪物度 肉度",
        recipe_count = 2
    }
end

------------
--食趣
------------

if not SETS_PASTORAL.ENABLEDMODS["tastefun"] then
    -- 草莓果冻
    foods_pl.tf_strawberry_jelly =
    {
        test = function(cooker, names, tags)
            return names.tf_strawberry == 3 and tags.frozen
        end,
        priority = 50,
        weight = 1,
        foodtype = FOODTYPE.VEGGIE,
        health = 30,
        hunger = 12.5,
        perishtime = 8 * TUNING.TOTAL_DAY_TIME,
        sanity = 60,
        cooktime = 1,
        floater = { "med", nil, 0.55 },
        card_def = { ingredients = { { "tf_strawberry", 3 }, { "ice", 1 } } },
        overridebuild = "dishes_pastoral", -- 放在自己的动画包里也没啥关系的
    }
    -- 草莓蛋挞
    foods_pl.tf_strawberry_tart =
    {
        test = function(cooker, names, tags)
            return names.tf_strawberry == 2 and tags.egg and tags.sweetener
        end,
        priority = 30,
        weight = 1,
        foodtype = FOODTYPE.GOODIES,
        health = 60,
        hunger = 33,
        perishtime = 12 * TUNING.TOTAL_DAY_TIME,
        sanity = 33,
        cooktime = 1,
        floater = { "med", nil, 0.55 },
        card_def = { ingredients = { { "tf_strawberry", 2 }, { "bird_egg", 1 }, { "honey", 1 } } },
        overridebuild = "dishes_pastoral",
    }
    -- 草莓冻奶布丁
    foods_pl.tf_strawberry_milk_pudding =
    {
        test = function(cooker, names, tags)
            return names.tf_strawberry == 2 and tags.frozen and tags.sweetener
        end,
        priority = 30,
        weight = 1,
        foodtype = FOODTYPE.GOODIES,
        health = 40,
        hunger = 12.5,
        perishtime = 12 * TUNING.TOTAL_DAY_TIME,
        sanity = 60,
        cooktime = 1,
        floater = { "med", nil, 0.55 },
        card_def = { ingredients = { { "tf_strawberry", 2 }, { "ice", 1 }, { "honey", 1 } } },
        overridebuild = "dishes_pastoral",
    }
    -- 草莓蛋糕
    foods_pl.tf_strawberry_cake =
    {
        test = function(cooker, names, tags)
            return names.tf_strawberry == 1 and tags.sweetener and tags.fat and tags.egg
        end,
        priority = 30,
        weight = 1,
        foodtype = FOODTYPE.GOODIES,
        health = 40,
        hunger = 112.5,
        perishtime = 12 * TUNING.TOTAL_DAY_TIME,
        sanity = 33,
        cooktime = 1,
        floater = { "med", nil, 0.55 },
        card_def = { ingredients = { { "tf_strawberry", 1 }, { "honey", 1 }, { "butter", 1 }, { "bird_egg", 1 } } },
        overridebuild = "dishes_pastoral",
    }
    -- 草莓水果派
    foods_pl.tf_strawberry_fruit_pie =
    {
        test = function(cooker, names, tags)
            return names.tf_strawberry == 1 and names.pomegranate == 1 and tags.sweetener and tags.fat
        end,
        priority = 30,
        weight = 1,
        foodtype = FOODTYPE.GOODIES,
        health = 75,
        hunger = 75,
        perishtime = 12 * TUNING.TOTAL_DAY_TIME,
        sanity = 75,
        cooktime = 1,
        floater = { "med", nil, 0.55 },
        card_def = { ingredients = { { "tf_strawberry", 1 }, { "pomegranate", 1 }, { "honey", 1 }, { "butter", 1 } } },
        overridebuild = "dishes_pastoral",
    }
    -- 橘子果汁
    foods_pl.tf_orange_juice =
    {
        test = function(cooker, names, tags)
            return names.tf_orange == 2 and tags.frozen and tags.frozen > 1
        end,
        priority = 30,
        weight = 1,
        foodtype = FOODTYPE.VEGGIE,
        health = 15,
        hunger = 25,
        perishtime = 8 * TUNING.TOTAL_DAY_TIME,
        sanity = 30,
        cooktime = 1,
        floater = { "med", nil, 0.55 },
        card_def = { ingredients = { { "tf_orange", 2 }, { "ice", 2 } } },
        overridebuild = "dishes_pastoral",
    }
    -- 草莓甜甜圈
    foods_pl.tf_strawberry_donut =
    {
        test = function(cooker, names, tags)
            return names.tf_strawberry and tags.sweetener and tags.fat and tags.fat > 1
        end,
        priority = 30,
        weight = 1,
        foodtype = FOODTYPE.GOODIES,
        health = 60,
        hunger = 112.5,
        perishtime = 20 * TUNING.TOTAL_DAY_TIME,
        sanity = 93.5,
        cooktime = 1,
        floater = { "med", nil, 0.55 },
        card_def = { ingredients = { { "tf_strawberry", 1 }, { "honey", 1 }, { "butter", 2 } } },
        overridebuild = "dishes_pastoral",
    }
    -- 草莓汽水
    foods_pl.tf_strawberry_soda =
    {
        test = function(cooker, names, tags)
            return names.tf_strawberry == 2 and tags.frozen and tags.frozen > 1
        end,
        priority = 30,
        weight = 1,
        foodtype = FOODTYPE.GOODIES,
        health = 3,
        hunger = 12.5,
        perishtime = 20 * TUNING.TOTAL_DAY_TIME,
        sanity = 33,
        cooktime = 1,
        floater = { "med", nil, 0.55 },
        card_def = { ingredients = { { "tf_strawberry", 2 }, { "ice", 2 } } },
        overridebuild = "dishes_pastoral",
    }
    -- 地三鲜
    foods_pl.tf_earth_three_delicacies =
    {
        test = function(cooker, names, tags)
            return names.eggplant == 1 and names.potato == 2 and names.tf_green_pepper == 1
        end,
        priority = 30,
        weight = 1,
        foodtype = FOODTYPE.VEGGIE,
        health = 12.5,
        hunger = 82.5,
        perishtime = 15 * TUNING.TOTAL_DAY_TIME,
        sanity = 15,
        cooktime = 1,
        floater = { "med", nil, 0.55 },
        card_def = { ingredients = { { "eggplant", 1 }, { "potato", 2 }, { "tf_green_pepper", 1 } } },
        overridebuild = "dishes_pastoral",
    }
    -- 白菜猪肉炖粉条
    foods_pl.tf_pork_cabbage_glass_noodle_stew =
    {
        test = function(cooker, names, tags)
            return tags.meat and tags.meat >= 2 and names.tf_cabbage == 2
        end,
        priority = 30,
        weight = 1,
        foodtype = FOODTYPE.MEAT,
        health = 30,
        hunger = 125.5,
        perishtime = 15 * TUNING.TOTAL_DAY_TIME,
        sanity = 15,
        cooktime = 1,
        floater = { "med", nil, 0.55 },
        card_def = { ingredients = { { "meat", 2 }, { "tf_cabbage", 2 } } },
        overridebuild = "dishes_pastoral",
    }
end

------------
--荔只只物语
------------

if not SETS_PASTORAL.ENABLEDMODS["lz"] then
    -- 桃花醉
    foods_pl.lz_taohuazui =
    {
        test = function(cooker, names, tags)
            return (names.lz_lizhi and names.lz_lizhi or names.lz_lizhi_cooked and names.lz_lizhi_cooked >= 3) and names.ice and not tags.meat
        end,
        priority = 115,
        weight = 1,
        foodtype = FOODTYPE.GOODIES,
        health = 5,
        hunger = 5,
        perishtime = 8 * TUNING.PERISH_ONE_DAY,
        sanity = 5,
        cooktime = 6 / 4,
        oneat_desc = "桃花醉",
        oneatenfn = function(inst, eater)
            if eater.components.debuffable ~= nil and
                eater.components.debuffable:IsEnabled() and
                not (eater.components.health ~= nil and eater.components.health:IsDead()) and
                not eater:HasTag("playerghost") then
                eater.components.debuffable:AddDebuff("lz_taohuazui_buff", "lz_taohuazui_buff")
            end
        end,
        overridebuild = "dishes_pastoral",
    }
end

-- 2024年11月新增物品
foods_pl.blue_nightberrycake = {
    test = function(cooker, names, tags) -- 烹饪配方函数
        return names.ancientfruit_nightvision == 2 and (names.gzresource_apple or names.gzresource_apple_cooked or names.gzresource_apple_advanced)
            and (names.piggymimosa or names.piggymimosa_cooked)
    end,
    priority = priority_med,              -- 料理优先级
    foodtype = FOODTYPE.GOODIES,          -- 食物类型
    perishtime = TUNING.PERISH_SUPERFAST, -- 腐烂时间/天
    hunger = 20,
    sanity = 5,
    health = 0,
    cooktime = 0.8,                           -- 烹饪时间/s
    float = { nil, "small", 0.2, 1.05 },      -- 设置料理漂浮水面的数据
    potlevel = "low",                         -- 动画在烹饪锅的位置高低,建议一个mod中所有料理固定一个值
    prefabs = { "buff_pl_nightvision" },      -- 该料理被注册为预制物之前需要先加载的预制物
    -- tags = { "honeyed" }, -- 将被添加到预制物的tags
    oneat_desc = "",                          -- 烹饪指南中会显示的描述语
    oneatenfn = function(inst, eater)         -- 食用后执行的函数，在此实现buff
        if eater.components.playervision then -- 这个buff需要攻击组件
            eater.buff_pl_nightvision = { add = TUNING.SEG_TIME * 16, max = TUNING.SEG_TIME * 30 }
            eater:AddDebuff("buff_pl_nightvision", "buff_pl_nightvision")
        end
    end,
    card_def = { ingredient = { { "ancientfruit_nightvision", 2 }, { "gzresource_apple", 1 }, { "piggymimosa", 1 } } }, -- 将生成对应的食谱卡
    overridebuild = "blue_nightberrycake",
    isMasterfood = false,                                                                                               -- 是否大厨料理
    maxstacksize = 40,                                                                                                  -- 最大堆叠数量
    onperishreplacement = nil,                                                                                          -- 腐烂产物，默认为腐烂物
    perishfn = nil,                                                                                                     -- 腐烂时的回调函数
}

foods_pl.sea_swallow = {
    test = function(cooker, names, tags) --烹饪配方函数
        return names.malbatross_feather == 2 and (names.yq_jiang or names.yq_jiang_cooked)
            and (names.yq_baicai or names.yq_baicai_cooked)
    end,
    priority = priority_med,            -- 料理优先级
    foodtype = FOODTYPE.GOODIES,        -- 食物类型
    perishtime = TUNING.PERISH_FASTISH, -- 腐烂时间/天
    hunger = 5,
    sanity = 5,
    health = 5,
    cooktime = 0.8,                       -- 烹饪时间/s
    float = { nil, "small", 0.2, 1.05 },  -- 设置料理漂浮水面的数据
    potlevel = "low",                     -- 动画在烹饪锅的位置高低,建议一个mod中所有料理固定一个值
    prefabs = { "buff_pl_waterwalking" }, -- 该料理被注册为预制物之前需要先加载的预制物
    -- tags = { "honeyed" }, -- 将被添加到预制物的tags
    oneat_desc = "",                      -- 烹饪指南中会显示的描述语
    oneatenfn = function(inst, eater)     -- 食用后执行的函数，在此实现buff
        if eater.components.drownable then
            eater.buff_pl_waterwalking = { add = TUNING.SEG_TIME * 16, max = TUNING.SEG_TIME * 30 }
            eater:AddDebuff("buff_pl_waterwalking", "buff_pl_waterwalking")
        end
    end,
    card_def = { ingredient = { { "malbatross_feather", 2 }, { "yq_jiang", 1 }, { "yq_baicai", 1 } } }, -- 将生成对应的食谱卡
    overridebuild = "sea_swallow",
    isMasterfood = false,                                                                               -- 是否大厨料理
    maxstacksize = 40,                                                                                  -- 最大堆叠数量
    onperishreplacement = nil,                                                                          -- 腐烂产物，默认为腐烂物
    perishfn = nil,                                                                                     -- 腐烂时的回调函数
}
foods_pl.delicious_chowder = {
    test = function(cooker, names, tags) -- 烹饪配方函数
        return (names.yq_dacong or names.yq_dacong_cooked) and (names.yq_jiang or names.yq_jiang_cooked)
            and (names.yq_bocai or names.yq_bocai_cooked) and (names.piggymimosa or names.piggymimosa_cooked)
    end,
    priority = priority_hig,            -- 料理优先级
    foodtype = FOODTYPE.GOODIES,        -- 食物类型
    perishtime = TUNING.PERISH_MED / 2, -- 腐烂时间/天
    hunger = 5,
    sanity = 5,
    health = 5,
    cooktime = 0.8,                           -- 烹饪时间/s
    float = { nil, "small", 0.2, 1.05 },      -- 设置料理漂浮水面的数据
    potlevel = "low",                         -- 动画在烹饪锅的位置高低,建议一个mod中所有料理固定一个值
    prefabs = { "buff_pl_deliciouschowder" }, -- 该料理被注册为预制物之前需要先加载的预制物
    -- tags = { "honeyed" }, -- 将被添加到预制物的tags
    oneat_desc = "",                          -- 烹饪指南中会显示的描述语
    oneatenfn = function(inst, eater)         -- 食用后执行的函数，在此实现buff
        if eater.components.eater then
            eater.buff_pl_deliciouschowder = { add = TUNING.SEG_TIME * 16, max = TUNING.SEG_TIME * 30 }
            eater:AddDebuff("buff_pl_deliciouschowder", "buff_pl_deliciouschowder")
        end
    end,
    card_def = { ingredient = { { "yq_dacong", 1 }, { "yq_jiang", 1 }, { "piggymimosa", 1 }, { "yq_bocai", 1 } } }, -- 将生成对应的食谱卡
    overridebuild = "delicious_chowder",
    isMasterfood = false,                                                                                           -- 是否大厨料理
    maxstacksize = 40,                                                                                              -- 最大堆叠数量
    onperishreplacement = nil,                                                                                      -- 腐烂产物，默认为腐烂物
    perishfn = nil,                                                                                                 -- 腐烂时的回调函数
}
------
------

-- for k, v in pairs(foods_pl) do
--     v.name = k
--     v.basename = v.basename or k -- 料理的基础名称。用于生成预制物的名称
--     if v.weight == nil then
--         v.weight = 1
--     end
--     if v.priority == nil then
--         v.priority = priority_low
--     end
--     v.overridebuild = v.overridebuild or k
--     -- v.overridesymbolname = nil, -- 替换烹饪锅的料理贴图的symbol。默认与料理名同名
--     if v.oneatenfn ~= nil and v.oneat_desc == nil then
--         v.oneat_desc = STRINGS.UI.COOKBOOK[string.upper(k)]
--     end
--     if v.cookbook_tex == nil then -- 食谱大图所用的image
--         v.cookbook_tex = k .. ".tex"
--     end
--     if v.cookbook_atlas == nil then -- 食谱大图所用的atlas
--         v.cookbook_atlas = "images/cookbookimages/" .. k .. ".xml"
--     end
--     -- v.cookbook_category = "mod" -- 官方在AddCookerRecipe时就设置了，所以，cookbook_category 不需要自己写
-- end

for k, v in pairs(foods_pl) do
    v.name = k
    v.basename = k
    v.weight = v.weight or 1
    v.priority = v.priority or priority_low
    v.overridebuild = v.overridebuild or k
    v.cookbook_category = "cookpot"

    --烹饪指南里的料理贴图
    if v.cookbook_atlas == nil then
        v.cookbook_atlas = "images/cookbook_images/" .. k .. ".xml"
    end
    if v.cookbook_tex == nil then
        v.cookbook_tex = "" .. k .. ".tex"
    end
end

return foods_pl
